package com.achievement.entity.dto;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.springframework.data.jpa.domain.Specification;

import com.achievement.entity.Course;
import com.achievement.entity.Subject;
import com.user.entity.Teacher;

public class StuCourseDTO {
	private Long id;
	private String num;
	private String name;
	private String subject;
	private String teacher;
	private boolean selected;
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public String getNum() {
		return num;
	}
	public void setNum(String num) {
		this.num = num;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getSubject() {
		return subject;
	}
	public void setSubject(String subject) {
		this.subject = subject;
	}
	public String getTeacher() {
		return teacher;
	}
	public void setTeacher(String teacher) {
		this.teacher = teacher;
	}
	
	public boolean isSelected() {
		return selected;
	}
	public void setSelected(boolean selected) {
		this.selected = selected;
	}
	
	public StuCourseDTO(Course course,boolean selected) {
		super();
		this.id = course.getId();
		this.num = course.getNum();
		this.name = course.getName();
		this.subject = course.getSubject().getName();
		this.teacher = course.getTeacher().getName();
		this.selected = selected;
	}
	public StuCourseDTO() {
		super();
	}
	public static Specification<Course> getSpecification() {
		Specification<Course> spec = new Specification<Course>() {
			public Predicate toPredicate(Root<Course> root, CriteriaQuery<?> query, CriteriaBuilder cb) {

				List<Predicate> list = new ArrayList<Predicate>();
				Predicate[] p = new Predicate[list.size()];
				return cb.and(list.toArray(p));
			}
		};
		return spec;
	}
}
